import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);

const store = new Vuex.Store({
	state: {
		isAlreadyLogin: false,
		requestOption: undefined,
		openid: undefined,
		fzr: undefined,
		sqs: undefined,
		dz: undefined,
		dzs: undefined,
		location: undefined,
		locationFlg: false,
		position: undefined
	},
	mutations: {
		submitOpenid(state, openid) {
			state.openid = openid;
		},
		setPosition(state, position) {
			state.position = position;
		},
		setLocation(state, location) {
			if (location && location.provice) {
				state.position = {
					jd: location.provice.lng,
					wd: location.provice.lat
				}
			}
			
			if (location && location.city) {
				state.position = {
					jd: location.city.lng,
					wd: location.city.lat
				}
			}
			state.location = location;
			state.locationFlg = true;
		},
		removeLocation(state) {
			state.location = undefined;
			state.locationFlg = false;
		},
		submitDzs(state, dzs) {
			state.dzs = dzs;
		},
		submitDz(state, dz) {
			state.dz = dz;
		},
		submitFzr(state, fzr) {
			state.fzr = fzr;
		},
		loginSuccess(state, autor) {
			state.isAlreadyLogin = true;
			state.openid = autor.openid;
			state.fzr = autor.acomfzr;
			state.dz = autor.adz;
			state.dzs = autor.adzs;
			state.sqs = autor.sqs;
			if (state.requestOption) {
				state.requestOption.header["Cookie"] = "JSESSIONID="+state.sessionId;
				uni.request(state.requestOption);
				state.requestOption = undefined;
			}
		},
		loginOut(state) {
			state.isAlreadyLogin = false;
		}
	}
});
export default store;